package com.icloud.system.boot.controller.admin;

import com.icloud.common.core.api.CommonResult;
import com.icloud.common.web.annotation.AdminOperationLog;
import com.icloud.common.web.annotation.Permission;
import com.icloud.system.boot.dto.AdminPermissionSaveDto;
import com.icloud.system.boot.dto.AdminPermissionStateSetDto;
import com.icloud.system.boot.service.AdminPermissionService;
import com.icloud.system.boot.vo.AdminPermissionTreeVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

//@RestController
//@Api(tags = "后台权限管理")
//@RequestMapping("/admin/permission")
@RequiredArgsConstructor
public class AdminPermissionController {
    private final AdminPermissionService permissionService;

    //@Permission("system.adminPermission.list")
    //@ApiOperation("权限列表")
    //@GetMapping(value = "/list")
    public CommonResult<List<AdminPermissionTreeVo>> getList() {
        return CommonResult.success(permissionService.getTreePermission(true));
    }

    //@ApiOperation("获取所有权限，供给角色分配权限时提供渲染数据")
    //@GetMapping(value = "/all")
    public CommonResult<List<AdminPermissionTreeVo>> getAllPermission() {
        return CommonResult.success(permissionService.getTreePermission(false));
    }

    //@AdminOperationLog(value = "账号管理-权限管理-添加权限")
    //@ApiOperation("添加权限")
    //@PostMapping(value = "/add")
    //@Permission("system.adminPermission.add")
    public CommonResult<Void> addPermission(@Validated @RequestBody AdminPermissionSaveDto dto) {
        permissionService.addPermission(dto);
        return CommonResult.success();
    }

    //@AdminOperationLog(value = "账号管理-权限管理-删除权限")
    //@ApiOperation("删除权限")
    //@DeleteMapping(value = "/delete/{id}")
    //@Permission("system.adminPermission.delete")
    public CommonResult<Void> delPermission(@ApiParam("权限id") @PathVariable("id") Long id) {
        permissionService.deletePermission(id);
        return CommonResult.success();
    }

    //@Permission(value = "system.adminPermission.updateStatus")
    //@AdminOperationLog(value = "账号管理-权限管理-状态切换")
    //@ApiOperation("状态切换")
    //@PostMapping(value = "/status")
    public CommonResult<Void> setPermissionStatus(@Validated @RequestBody AdminPermissionStateSetDto dto) {
        permissionService.batchSetPermissionStatus(dto.getIds(), dto.getState());
        return  CommonResult.success();
    }
}
